# -*- encoding:utf-8 -*-
# @time: 2023/3/18 16:53
# @author: Maxs_hu
# -*- encoding:utf-8 -*-
# @time: 2023/3/14 21:58
# @author: Maxs_hu
from tencentcloud.common import credential
from tencentcloud.sms.v20210111 import sms_client, models
import random


def send_sms(mobile):
    cred = credential.Credential("AKID7EKbnhR8sW0MctJaljbJrjaQMl9QXXQH", "qQzPNKuCYtnhXHRSTWqFrS0XUTJ2eTaU")
    client = sms_client.SmsClient(cred, "ap-guangzhou")

    req = models.SendSmsRequest()

    req.SmsSdkAppId = "1400802599"
    req.SignName = "iifeng公众号"
    req.TemplateId = "1730182"
    sms = ''
    for item in range(6):
        res = random.randint(0, 9)
        sms += str(res)

    req.TemplateParamSet = [sms, '1']  # 和变量个数一致
    req.PhoneNumberSet = ["+86" + mobile]

    resp = client.SendSms(req)
    # print(resp)
    """
    {"SendStatusSet": [{"SerialNo": "3369:347023964716791303394043639", "PhoneNumber": "+8618355136393", "Fee": 1, "SessionContext": "", "Code": "Ok", "Message": "send success", "IsoCode": "CN"}], "RequestId": "a0a305d8-1167-416c-a173-2366c6a0bc78"}
    {"SendStatusSet": [{"SerialNo": "", "PhoneNumber": "+8618355136393", "Fee": 0, "SessionContext": "", "Code": "LimitExceeded.PhoneNumberThirtySecondLimit", "Message": "the number of SMS messages sent from a single mobile number within 30 seconds exceeds the upper limit", "IsoCode": "CN"}], "RequestId": "70deb880-d75a-4fbb-8765-5ce96f30f06b"}

    """
    # if resp.SendStatusSet[0].Code == 'ok':
    #     return sms, True
    return sms, resp.SendStatusSet[0].Code


